﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TJLTVK02
    {
        ITXEXRPT ITXEXRPT;
        public TJLTVK02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVKPOS();
            this.DataContext = MV;
            InitializeComponent();
            ITXEXRPT = new ITXEXRPT();
            ITXEXRPT.Root = "C:\\IntexReport";
            ITXEXRPT.strCompany = app.company;
            ITXEXRPT.PrintType = "OpenExcel";
        }

        public override void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {

            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
            DTSTART = Helpers.Helper.GetDateAddDays(MV.date, -365);
            DTEND = Helpers.Helper.GetDateAddDays(MV.date, 120);
            NEUDATS = Helpers.Helper.GetDateAddDays(MV.date, -365);
            NEUDATE = MV.date;
            IsShowMaster = true;
            IsShowSY = false;
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            if (dwMain == null)
            {
            }
            if (dwMaster == null)
            { 
                VART = "";
                TXTISIND = ""; 
                MEEH = "".PadRight(3);
                AUF = "";
                POSTYP = "";
                KUNDNR = "";
            }
            else
            {
                KUNDNR = TMV.VKPKUNDNR;              
                MEEH = TMV.VKPMEEH;
                POSTYP = TMV.VKPPOSTYP;               
                VART = TMV.VKPKOLL + TMV.VKPART + TMV.VKPFARBE; 
                TXTISIND = (TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS + "VKT").PadRight(60);                
                AUF = "K" + TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS + LIEFSCH.PadRight(8);
            }       
        }
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            dwData["VKPMANDANT"] = app.Mandant;
            if (KUNDNR == "000000")
            {
                KUNDNR = "";
            }
            if (DTSTART == "")
            {
                DTSTART = "20010101";
            }
            if (DTEND == "")
            {
                DTEND = "20990101";
            }
            if (NEUDATS == "")
            {
                NEUDATS = "20010101";
            }
            if (NEUDATE == "")
            {
                NEUDATE = "20990101";
            }
            dwData["VKPKUNDNR"] = " AND VKPKUNDNR LIKE '" + KUNDNR + "%'";
            dwData["VKPPOSTYP"] = " AND VKKAUFART LIKE '" + AUFART + "%'";
            dwData["VKPKDKOMM"] = " AND VKPKDKOMM LIKE '" + KDKOMM + "%'";
            dwData["VKPSACHBE"] = " AND VKPSACHBE LIKE'" + SACHBE + "%'";
            dwData["VKPFILLER2"] = " AND VKPLIEFTERM>='" + DTSTART + "' AND VKPLIEFTERM<='" + DTEND + "'";
            dwData["VKPNEUBEN"] = " AND VKPNEUDAT>='" + NEUDATS + "' AND VKPNEUDAT<='" + NEUDATE + "'";
            dwData["VKPART"] = " AND VKPKOLL LIKE '" + KOLL.Trim() + "%' AND VKPART LIKE '" + ART.Trim() + "%' AND VKPFARBE LIKE '" + FARBE.Trim() + "%'";
            if (LFD == "000000")
            {
                LFD = "";
            }
            dwData["VKPAUFLFD"] = "AND VKPAUFKRS LIKE '" + KRS.Trim() + "%' AND VKPAUFLFD LIKE '%" + LFD.Trim() + "%'";
            SResult = TMV.QVKP23JLT(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
        }
        private void PrintCommand(object sender, RoutedEventArgs e)
        {
            ITXEXRPT.dsSource = TBMain.DataSet;
            ITXEXRPT.DocType = "JLTVK02XSR";
            ITXEXRPT.strExcelFile = app.company + @"\YGRVKPOS.xls";
            string filename = ITXEXRPT.WriteExcelReport();

        }
    }
}
